home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / sys5 / iscwmpst.z / iscwmpst / tcp / src / services.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-19  |  3.4 KB  |  150 lines

  1. /* @(#) $Header: services.c,v 1.2 91/06/18 17:27:27 deyke Exp $ */
  2.  
  3. #include <ctype.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #include "global.h"
  8. #include "socket.h"
  9. #include "netuser.h"
  10.  
  11. struct port_table {
  12.   char  *name;
  13.   int  port;
  14. };
  15.  
  16. static struct port_table tcp_port_table[] = {
  17.   "*",           0,
  18.   "convers",     3600,
  19.   "discard",     IPPORT_DISCARD,/* ARPA discard protocol */
  20.   "echo",        IPPORT_ECHO,   /* ARPA echo protocol */
  21.   "finger",      IPPORT_FINGER, /* ARPA finger protocol */
  22.   "ftp",         IPPORT_FTP,    /* ARPA file transfer protocol (cmd) */
  23.   "ftp-data",    IPPORT_FTPD,   /* ARPA file transfer protocol (data) */
  24.   "netupds",     4715,
  25.   "nntp",        IPPORT_NNTP,
  26.   "pop2",        IPPORT_POP,    /* Post Office Prot. v2 */
  27.   "smtp",        IPPORT_SMTP,   /* ARPA simple mail transfer protocol */
  28.   "telnet",      IPPORT_TELNET, /* ARPA virtual terminal protocol */
  29.   "ttylink",     IPPORT_TTYLINK,
  30.   NULLCHAR
  31. };
  32.  
  33. static struct port_table udp_port_table[] = {
  34.   "*",           0,
  35.   "bootpc",      IPPORT_BOOTPC,
  36.   "bootps",      IPPORT_BOOTPS,
  37.   "domain",      IPPORT_DOMAIN, /* ARPA domain nameserver */
  38.   "remote",      IPPORT_REMOTE,
  39.   "rip",         IPPORT_RIP,
  40.   "stime",       4713,
  41.   NULLCHAR
  42. };
  43.  
  44. static char *nextstr __ARGS((void));
  45. static char *port_name __ARGS((struct port_table *table, int port));
  46. static int port_number __ARGS((struct port_table *table, char *name));
  47.  
  48. /*---------------------------------------------------------------------------*/
  49.  
  50. static char  *nextstr()
  51. {
  52.  
  53. #define NUMSTR  16
  54.  
  55.   static char  strstore[NUMSTR][128];
  56.   static int  strindex;
  57.  
  58.   strindex++;
  59.   if (strindex >= NUMSTR) strindex = 0;
  60.   return strstore[strindex];
  61. }
  62.  
  63. /*---------------------------------------------------------------------------*/
  64.  
  65. static char  *port_name(table, port)
  66. struct port_table *table;
  67. int  port;
  68. {
  69.   char  *p;
  70.  
  71.   for (; table->name; table++)
  72.     if (port == table->port) return table->name;
  73.   p = nextstr();
  74.   sprintf(p, "%u", port);
  75.   return p;
  76. }
  77.  
  78. /*---------------------------------------------------------------------------*/
  79.  
  80. char  *tcp_port_name(port)
  81. int  port;
  82. {
  83.   return port_name(tcp_port_table, port);
  84. }
  85.  
  86. /*---------------------------------------------------------------------------*/
  87.  
  88. char  *udp_port_name(port)
  89. int  port;
  90. {
  91.   return port_name(udp_port_table, port);
  92. }
  93.  
  94. /*---------------------------------------------------------------------------*/
  95.  
  96. static int  port_number(table, name)
  97. struct port_table *table;
  98. char  *name;
  99. {
  100.   int  len;
  101.  
  102.   if (!isdigit(uchar(*name))) {
  103.     len = strlen(name);
  104.     for (; table->name; table++)
  105.       if (!strncmp(name, table->name, len)) return table->port;
  106.   }
  107.   return atoi(name);
  108. }
  109.  
  110. /*---------------------------------------------------------------------------*/
  111.  
  112. int  tcp_port_number(name)
  113. char  *name;
  114. {
  115.   return port_number(tcp_port_table, name);
  116. }
  117.  
  118. /*---------------------------------------------------------------------------*/
  119.  
  120. int  udp_port_number(name)
  121. char  *name;
  122. {
  123.   return port_number(udp_port_table, name);
  124. }
  125.  
  126. /*---------------------------------------------------------------------------*/
  127.  
  128. char  *pinet_tcp(s)
  129. struct socket *s;
  130. {
  131.   char  *p;
  132.  
  133.   p = nextstr();
  134.   sprintf(p, "%s:%s", inet_ntoa(s->address), tcp_port_name(s->port));
  135.   return p;
  136. }
  137.  
  138. /*---------------------------------------------------------------------------*/
  139.  
  140. char  *pinet_udp(s)
  141. struct socket *s;
  142. {
  143.   char  *p;
  144.  
  145.   p = nextstr();
  146.   sprintf(p, "%s:%s", inet_ntoa(s->address), udp_port_name(s->port));
  147.   return p;
  148. }
  149.  
  150.